home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
simula
/
books
/
books.lha
/
kirkerud
/
skater.sim
< prev
next >
Wrap
Text File
|
1993-08-16
|
2KB
|
71 lines
! Proposed solution to exercise 3.9;
begin
integer distance, divisor,
skater, best_skater,
minutes, best_minutes;
Boolean more_skaters;
real seconds, points, best_points, best_seconds;
outtext("Enter the distance: "); breakoutimage; inimage;
distance := inint;
if not (distance = 500 or distance = 1000 or distance = 1500 or
distance = 3000 or distance = 5000 or distance = 10000)
then begin
outtext("Illegal distance: "); outint(distance, 0); outimage;
outtext("Legal distances are"); outimage;
outtext(" 500, 1500, 5000 and 10000 for men"); outimage;
outtext(" 500, 1000, 1500 and 3000 for women"); outimage;
end of illegal distance
else begin
outtext("Enter the times used as follows:"); outimage;
outtext(" 7 1.55 for 7 minutes, 1.55 seeconds"); outimage;
outtext("Enter a negative number after the last skater"); outimage;
divisor := distance/500;
skater := 0;
best_points := 1000;
more_skaters := true;
while more_skaters do
begin
skater := skater + 1;
outtext("Enter time for skater nr. "); outint(skater, 0);
outtext(": "); breakoutimage; inimage;
minutes := inint;
if minutes < 0 then more_skaters := false
else begin
seconds := inreal;
points := (minutes*60 + seconds)/divisor;
outtext("Points: "); outfix(points, 3, 7); outimage;
if points < best_points then
begin
best_points := points;
best_minutes := minutes; best_seconds := seconds;
best_skater := skater;
end of points < best_points;
end of not minutes < 0;
end of more_skaters;
outtext("Scores were calculated for ");
outint(skater - 1, 0); outtext(" skaters"); outimage;
if skater > 1 then
begin
outtext("The best time: ");
outint(best_minutes, 0); outtext(" minute");
if best_minutes > 1 then outtext("s, ") else outtext(", ");
outfix(best_seconds, 2, 0);
outtext(" seconds (skater nr. ");
outint(best_skater, 0); outtext(")"); outimage;
end of skater > 1;
end of legal distance;
end of program